package com.ruoyi.web.controller.wechat;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.WxLoginParam;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName WxLoginController
 * @Author 任宝坤
 * @Date 2025/9/28 16:08
 * @Version v1.0
 **/

@RestController
@RequestMapping("/wx")
public class WxLoginController extends BaseController {

    @GetMapping("/login")
    public AjaxResult login(@RequestParam("code") String code){
        if (StringUtils.isNotBlank(code)){
            WxLoginParam pre = WxLoginParam.pre(code);
            String result = HttpUtils.sendGet(pre.getLoginUrl(), "appid=" + pre.getAppId() + "&secret=" + pre.getAppSecret() + "&grant_type=authorization_code&js_code=" + pre.getJs_code());
            System.out.println(result);
        }
        return error("未获取到微信登录的code，请重试~");
    }
}
